﻿using Grpc.Core;
using Grpc.Net.Client;
using ProtoBuf.Grpc;
using ProtoBuf.Grpc.Client;
using ProtoBuf.Grpc.Configuration;
using ProtobufNetShared;
using System.Runtime.Serialization;
using System.ServiceModel;

namespace ProtobufNetDemo
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            using var channel = GrpcChannel.ForAddress("http://localhost:5041");
            var client = channel.CreateGrpcService<IGreeterService>();
            var reply = await client.SayHelloAsync(
            new HelloRequest { Name = "Karl" });

            Console.WriteLine($"Greeting: {reply.Message}");
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
    }

    [DataContract]
    public class MultiplyRequest 
    {
        [DataMember(Order = 1)]
        public int X { get; set; }

        [DataMember(Order = 2)]
        public int Y { get; set; }  
    }

    [DataContract]
    public class MultiplyResult 
    {
        [DataMember(Order = 1)]
        public int Result { get; set; }
    }


    [Service("bar")]
    interface IBar 
    {
        Task B();
    }

    [Service("foo")]
    interface IFoo : IBar
    {
        Task A(); 
    }

    [Service("blap")]
    interface IBlap : IBar 
    {
        Task C();
    }

    [ServiceContract(Name = "Hyper.Calculator")]
    public interface ICalculator
    {
        ValueTask<MultiplyResult> MultiplyAsync(MultiplyRequest request, CallContext context = default);
    }


    public class MyCalculator : ICalculator
    {
        public ValueTask<MultiplyResult> MultiplyAsync(MultiplyRequest request, CallContext context = default)
        {
            return new ValueTask<MultiplyResult>(new MultiplyResult { Result = request.X * request.Y });
        }
    }

}
